/**
 * Project Name:demo
 * File Name:SwaggerConfig.java
 * Package Name:cn.bluemobi.demo.controller
 * Date:2015年11月30日下午4:33:50
 * Copyright (c) 2015, bluemobi.cn All Rights Reserved.
 *
 */

package cn.bluemobi.app.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import com.mangofactory.swagger.configuration.SpringSwaggerConfig;
import com.mangofactory.swagger.models.dto.ApiInfo;
import com.mangofactory.swagger.paths.SwaggerPathProvider;
import com.mangofactory.swagger.plugin.EnableSwagger;
import com.mangofactory.swagger.plugin.SwaggerSpringMvcPlugin;

/**
 * Description: <br/>
 * Date: 2015年11月30日 下午4:33:50 <br/>
 * 
 * @author hut
 * @version
 * @see
 */
@Configuration
@EnableSwagger
@ComponentScan(basePackages = { "com.mangofactory.swagger" })
public class SwaggerConfig {
    private SpringSwaggerConfig springSwaggerConfig;

    /**
     * Required to autowire SpringSwaggerConfig
     */
    @Autowired
    public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
        this.springSwaggerConfig = springSwaggerConfig;
    }

    /**
     * Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc
     * framework - allowing for multiple swagger groups i.e. same code base
     * multiple swagger resource listings.
     */
    @Bean
    public SwaggerSpringMvcPlugin customImplementation() {
        SwaggerSpringMvcPlugin plugin = new SwaggerSpringMvcPlugin(this.springSwaggerConfig);
        plugin.apiInfo(apiInfo());
        plugin.includePatterns(".*");
        // GtPaths path = new GtPaths();
        // plugin.pathProvider(path);
        return plugin;
    }

    private ApiInfo apiInfo() {
        ApiInfo apiInfo = new ApiInfo("康祺项目的api", "具体的api描述", "http://localhost:8080/kq-app/api", "tao.hu@Bluemobi.cn",
                "My Apps API Licence Type", "http://localhost:8080/kq-app");
        return apiInfo;
    }

    class GtPaths extends SwaggerPathProvider {

        @Override
        public String getOperationPath(String operationPath) {
            String path = super.getOperationPath(operationPath);
            return path + ".htm";
        }

        @Override
        protected String applicationPath() {
            return "/";
        }

        @Override
        protected String getDocumentationPath() {
            return "/";
        }
    }
}
